#include "../include/CacheManager.h"

void CacheManager::init() {
    _caches[0]->readToFile();
    allots();
}

void CacheManager::upsend() {
    //cout<<"缓存上送"<<endl;
    for (int k = 0; k < _caches[0]->_pendingcapacity; ++k) {
        for (int i = 0; i < _caches.size(); ++i) {
            if (!_caches[i]->_pendingUpdateList.empty()){
                cout<<i<<" ";
                cout<<_caches[i]->_pendingUpdateList.back().first<<endl;
                //_caches[i]->_pendingUpdateList.back().second;
                _caches[0]->put(_caches[i]->_pendingUpdateList.back().first,_caches[i]->_pendingUpdateList.back().second);
                _caches[i]->_pendingUpdateList.pop_back();
            }
        }
    }
    for(int i = 0;i<_caches.size();++i){
        _caches[i]->clearpending();
    }
}

void CacheManager::allots() {
    //cout<<"缓存下放"<<endl;
    for(int i = 1; i < _caches.size(); ++i){
        _caches[i]->_dlist = _caches[0]->_dlist;
        _caches[i]->_cache = _caches[0]->_cache;
    }
}

LRUCache* CacheManager::getcache(int name) {
    return _caches[name];
}